Paging = function(options){
	var _options =$.extend({},this._options,options);
	$.extend(this,{
		_options:_options
	});
	this._init();
};
Paging.prototype = {
		_options:{
			size:15,
			rows:0,
			index:1,
			form:"#form"
		},
		_sizeId:"_xl_paging_size",
		_indexId:"_xl_paging_index",
		_form:null,
		size:null,
		index:null,
		rows:null,
		last:null,
		first:null,
		prev:null,
		next:null,
		_init:function(){
			this._form = $(this._options.form);
			this.size = this._options.size;
			this.rows = this._options.rows;
			this.index = this._options.index;
			
			this._calculate();
			this.createInput();
		},
		_calculate:function(){
			this.last = Math.ceil(this.rows/this.size);
			this.first = this.rows >0?1:0;
			this.prev = this.index>this.first?this.index-1:0;
			this.next = this.index<this.last?this.index+1:this.last;
		},
		to:function(index){
			if((index>=this.first && index<=this.last) || index==1){
				window.app.loading.open();
				this.index = index;
				this.paging();
			}
		},
		toFirst:function(){
			this.to(this.first);
		},
		toLast:function(){
			this.to(this.last);
		},
		toPrev:function(){
			this.to(this.prev);
		},
		toNext:function(){
			this.to(this.next);
		},
		paging:function(){
			var sizeInput = $("#"+this._sizeId);
			var indexInput = $("#"+this._indexId);
			if(sizeInput.length>0){
				sizeInput.val(this.size);
				indexInput.val(this.index);
			}else{
				this.createInput();
			}
			this._form.submit();
		},
		createInput:function(){
			sizeInput = document.createElement("input");
			sizeInput.setAttribute("type", "hidden");
			sizeInput.setAttribute("id", this._sizeId);
			sizeInput.setAttribute("name", "size");
			sizeInput.setAttribute("value", this.size);

			indexInput = document.createElement("input");
			indexInput.setAttribute("type", "hidden");
			indexInput.setAttribute("id", this._indexId);
			indexInput.setAttribute("name", "index");
			indexInput.setAttribute("value", this.index);
			this._form.append(sizeInput);
			this._form.append(indexInput);
		},
		setSize:function(size){
			this.size = size;
			this.paging();
		},
		go:function(index){
			if(!isNaN(index)){
				index = parseInt(index);
				if(index>=0) this.to(index);
			}
		}
};